const http = require( 'http' );
const path = require( 'path' );
const fs = require( 'fs' );

const webRootFile = path.join( __dirname );

let mineType = {
    '.html': 'text/html;charset=utf-8',
    '.jpg': 'image/jpeg'
};

http.createServer( ( req, res ) => {
    let pathname = req.url;
    pathname = pathname === '/' ? '/index.html' : pathname;

    if ( pathname !== '/favicon.ico' ) {
        let webfilepath = path.join( webRootFile, pathname );
        if ( !fs.existsSync( webfilepath ) ) {
            res.statusCode = 404;
            res.end( fs.readFileSync( path.join( webRootFile, '404.html' ) ) );
        } else {
            let extname = path.extname( webfilepath );
           3333333333333333333
            res.end( fs.readFileSync( webfilepath ) );
        }
    }
} ).listen( 8080, () => {
    console.log( 'web启动' );
} )